package cn.beetech.demo;


import cn.beetech.demo.digest.AesUtils;
import cn.beetech.demo.digest.Digest;
import cn.beetech.demo.util.HttpExecResult;
import cn.beetech.demo.util.HttpExecUtils;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;

import java.util.HashMap;
import java.util.Map;


public class ApacheDemo {

    public static void main(String[] args) throws Exception {

        //bee tech提供
        String appId = "xxxx";
        String appSecretKey = "xxxxx";
        String aesKey = "xxxxx";
        String apiNo = "A001001";


        String idCard = "513723197607166961";
        String name = "张小翠";
        String phone = "13401254130";

        Map<String, Object> paraMap = new HashMap<>();
        paraMap.put("modelNumber", "L,CI");

        paraMap.put("idMd5", SecureUtil.md5(idCard));
        paraMap.put("phoneMd5", SecureUtil.md5(name));
        paraMap.put("nameMd5", SecureUtil.md5(phone));
        paraMap.put("idAes", AesUtils.encrypt(idCard, aesKey));
        paraMap.put("phoneAes", AesUtils.encrypt(name, aesKey));
        paraMap.put("nameAes", AesUtils.encrypt(phone, aesKey));
        paraMap.put("reqSerialNo", IdUtil.randomUUID());

        paraMap.put("sex", "1");
        paraMap.put("birthday", "1981/01/15");
        paraMap.put("insureProvince", "11");

        String timestamp = String.valueOf(DateUtil.current());
        paraMap.put("timestamp", timestamp);
        paraMap.put("productName", "bee0001");
        paraMap.put("productCode", "bee0001");
        paraMap.put("authorAgreementUrl", "https://xxxxx/xxx.pdf");
        paraMap.put("occupationName", "police");
        paraMap.put("occupationGrade", "6");


        //参数加签
        String digest = Digest.makeDigest(paraMap, timestamp, appSecretKey);
        paraMap.put("digest", digest);

        String url = "https://xxxxxx/api/v1/risk/TKE/" + apiNo + "/appid/" + appId + "/Base";


        final HttpExecResult httpExecResult = HttpExecUtils.doPost(url, paraMap, 3000);
        final String content = httpExecResult.getContent();

        System.out.println(content);

    }



}

